#include <iostream>
#include <unistd.h>
#include <signal.h>

int gcount = 0;
void hanlder(int signo)
{

    std::cout << "gcount : " << gcount << std::endl;
    int n = alarm(1); // 重设闹钟，会返回上⼀次闹钟的剩余时间
    std::cout << "剩余时间 : " << n << std::endl;
}
int main()
{
    alarm(1);
    signal(SIGALRM, hanlder);
    while (true)
    {
        pause();
        std::cout << "我醒来了..." << std::endl;
        gcount++;
    }
}